﻿
@model PH.Model.Schools.SchoolModel

<div class="GeneralEdit" id="fmSchool">
    <ul>
        <li>
            <label for="txtCode">学校编码：</label>
            <input type="text" class="k-textbox" id="txtCode" name="code" value="@Model.Code" maxlength="9" pattern="\d{9}" required validationMessage="请输入学校编码" />
            <span class="k-invalid-msg" data-for="code"></span>
        </li>
        <li>
            <label for="txtSchoolName">学校名称：</label>
            <input type="text" class="k-textbox" id="txtSchoolName" name="schoolName" value="@Model.SchoolName" maxlength="50" pattern=".{2,}" required validationMessage="请输入学校名称" />
            <span class="k-invalid-msg" data-for="schoolName"></span>
        </li>
        <li>
            <label for="selSchoolType">学校类型：</label>
            <select id="selSchoolType"></select>
        </li>
        <li>
            <label for="edBureau">所属机构：</label>
            <select id="edBureau"></select>
        </li>
        <li class="editButtons">
            <button id="btnSaveSchool" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="init">
    $(function () {
        $("#selSchoolType").kendoDropDownList({
            dataTextField: "Description",
            dataValueField: "ID",
            dataSource: Whale.dataSource({
                url: "/School/Config/GetSchoolTypes"
            }),
            dataBound: function (e) {
                var sel = $("#selSchoolType").data("kendoDropDownList");
                sel.select(function (dataItem) {
                    return dataItem.ID == "@Model.SchType";
                });
            }
        });

        $("#edBureau").kendoDropDownList({
            dataTextField: "EduName",
            dataValueField: "Guid",
            dataSource: bureaus,
            dataBound: function (e) {
                var sel = $("#edBureau").data("kendoDropDownList");
                sel.select(function (dataItem) {
                    return dataItem.Guid == "@Model.OwnerGuid";
                });
            }
        });
    });
</script>

<script class="save_school">
    $(function () {
        var validator = $("#fmSchool").kendoValidator().data("kendoValidator");
        $("#btnSaveSchool").click(function (e) {
            if (validator.validate()) {
                var values = {
                    guid: "@Model.Guid",
                    schoolName: $("#txtSchoolName").val(),
                    schType: $("#selSchoolType").data("kendoDropDownList").value(),
                    ownerGuid: $("#edBureau").data("kendoDropDownList").value(),
                    code:$("#txtCode").val()
                };

                Whale.Remote.Operation({
                    url: "/School/SchoolInfo/SaveSchool",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_school").length > 0)
                            $("#grid_school").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>